<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>创建用户</title>
   <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <script src="/static/lib/layui/layui.js"></script>
</head>
<style>

  </style>
<body>
<form class="layui-form">
    <div style="margin-top: 50px">
        <div class="layui-form-item layui-form-text" style="margin-top: 10px">
          <label class="layui-form-label">域标识</label>
          <div class="layui-input-block">
            <input type="text" name="name" id="domain_id" required  lay-verify="required" placeholder="请输入域标识" autocomplete="off" class="layui-input layui-disabled" style="width:400px" value={{request.session.domain_id}}>
          </div>
      </div>
        <div class="layui-form-item layui-form-text" style="margin-top: 10px">
      <label class="layui-form-label">域名</label>
      <div class="layui-input-block">
        <input type="text" name="name" id="domain_name" required  lay-verify="required" placeholder="请输入域名" autocomplete="off" class="layui-input layui-disabled" style="width:400px" value="default">
      </div>
  </div>
    <label class="layui-form-label">用户名</label>
      <div class="layui-input-block">
        <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" style="width:200px">
      </div>
     <div class="layui-form-item layui-form-text" style="margin-top: 10px">
      <label class="layui-form-label">描述</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" class="layui-textarea"  id="desc"  ></textarea>
      </div>
  </div>
        <div class="layui-form-item layui-form-text" style="margin-top: 10px">
                    <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-inline">
                        <input type="text"  name="email" id="email" lay-verify="email" autocomplete="off" class="layui-input">
                    </div>
                </div>
     <div class="layui-form-item" style="margin-top: 10px">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="password" name="password"  id="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
     </div>
    <div class="layui-form-item" style="margin-top: 10px">
    <label class="layui-form-label">确认密码</label>
    <div class="layui-input-inline">
      <input type="password" name="password" required lay-verify="required" placeholder="请再次输入密码" autocomplete="off" class="layui-input">
    </div>
     </div>
        <div class="layui-form-item" style="margin-top: 10px">
       <div class="layui-form-item">
     <label class="layui-form-label">主项目</label>
     <div class="layui-input-inline">
     <select name="orgType" lay-filter="Type_filter" id="otype" lay-verify="required">
         <option value="">选择项目</option>
     </select>
     </div>
            <button class="layui-btn layui-btn-normal  layui-btn-sm data-add-btn"  id="add_projects"> <i class="layui-icon" >&#xe654;</i></button>
     </div>
  </div>
    <div class="layui-form-item" style="margin-top: 10px">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-inline">
      <select name="city" lay-verify="">
      <option value="">user</option>
      <option value="010">admin</option>
    </select>
    </div>
  </div>

  </div>
  <button class="layui-btn layui-btn-normal"  style="margin-top: 20px; margin-left:65px" id="add_user" type="button">创建用户</button>
  <button class="layui-btn layui-btn-primary layui-border-blue" type="button" style="margin-top: 20px; margin-left:10px" id="cancel">取消</button>
</form>

<script>
    var $;
    var index = parent.layer.getFrameIndex(window.name);
    layui.use(['layer','form'], function(){
         $=layui.jquery;
             $('#cancel').on("click",function(){
            //获取当前窗口的name
                 parent.layer.close(index);//关闭窗口
             });
            $('#add_user').on("click",function(){
                 var user_name = $("#name").val()
                var desc = $("#desc").val()
                var email =$("#email").val()
                var pwd = $("#pwd").val()

                $.ajax({
                    url: "/zgh0381/user_create/",  // 请求的地址
                    type: "post",  // 请求方式
                    // 请求时传递过去的数据
                    data:{"user_name": user_name, "desc": desc, "email":email,"pwd":pwd},
                    dataType: "json",  // 返回的数据格式
                    async: true,  // 异步的ajax
                }).success(function (data) {
                    if(data.res == 1) {
                        layer.confirm('创建成功!', {icon: 1, title: '创建成功'}, function (index) {
                             layer.closeAll();
                        })
                    }
                    else if(data.res == 0){
                        // 请求失败，显示错误信息
                       layer.alert('创建失败!');
                    }

                })






     });
        //添加项目按钮
              $('#add_projects').on("click",function(){
                  parent.layer.open({
                         type: 2
                        ,offset:'auto'
                        ,title:'创建项目'
                        ,content:'/zgh0381/projectcreate/'
                        ,area:['1000px','700px']
                        ,btn:'关闭'
                        ,btnAlign:'c'
                        ,yes:function () {
                           parent.layer.closeAll();
                        }
                        ,end:function() {
                               location.reload();
                            }
                    });

             });




             $.ajax({
                 url: 'http://127.0.0.1:8000/zgh0381/pro_json/',
                 dataType: 'json',
                 data: {'state': 0},	//查询状态为正常的全部机构类型
                 type: 'post',
                 success: function (data) {
                     $.each(data.data, function (index, item) {
                         $('#otype').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                     });
                     layui.form.render("select");
                 }
             })



})


</script>

</body>
</html>
